﻿<navigation:Page xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"  
    x:Class="IndexMarkSilverlightClient.InputMain" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    xmlns:viewmodel="clr-namespace:IndexMarkSilverlightClient.Views"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
    xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             
    xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:classes="clr-namespace:IndexMarkSilverlightClient.Classes"
    xmlns:converters="clr-namespace:IndexMarkSilverlightClient.Classes.Converters"                 
    xmlns:sharedcontrols="clr-namespace:SharedCode.Controls;assembly=SharedCode"  
    xmlns:sys="clr-namespace:System;assembly=mscorlib"   
    xmlns:serviceref="clr-namespace:IndexMarkSilverlightClient.IndexMarkServiceReference"
    xmlns:sharedconverters="clr-namespace:SharedCode.Converters;assembly=SharedCode"
    xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    Title="Показатели ППС"
    Style="{StaticResource PageStyle}">

    <UserControl.Resources>
        <viewmodel:InputMainViewModel x:Key="InputMainViewModel" d:IsDataSource="True" />
        <converters:BoolToFontWeightConverter x:Key="BoolToFontWeightConverter"/>
        <converters:AnswerToVolumeConverter x:Key="AnswerToVolumeConverter"/>
        <classes:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
        <sharedconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <classes:ContrVisToBoolConverter x:Key="ContrVisToBoolConverter"/>
        <classes:UserToVisibilityConverter x:Key="UserToVisibilityConverter"/>

        <ControlTemplate x:Key="ToolTipTemplate">
            <Border CornerRadius="4" BorderBrush="#FF2754DD" BorderThickness="2" Background="#DDBADADA">
                <Grid Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Ellipse Fill="#FF7098D9" Height="32" Width="32"/>
                    <Ellipse Stroke="White" StrokeThickness="4" Fill="White" Height="30" Width="30"/>
                    <TextBlock Text="i" FontSize="24" FontWeight="Bold" VerticalAlignment="Center" FontFamily="Georgia" HorizontalAlignment="Center" Foreground="#FF7098D9"/>

                    <ContentPresenter Grid.Column="1"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}" 
                                      Margin="{TemplateBinding Padding}" 
                                      VerticalAlignment="Center"/>
                </Grid>
            </Border>
        </ControlTemplate>

        <Style x:Key="ToolTipTextBlockStyle" TargetType="TextBlock">
            <Setter Property="Margin" Value="2, 0, 0, 0"/>
            <Setter Property="Foreground" Value="DarkBlue"/>
        </Style>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">

        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="100" Width="3*" x:Name="TreeViewColumn" MaxWidth="600"/>
            <ColumnDefinition Width="8*" x:Name="DataGridColumn"/>
        </Grid.ColumnDefinitions>

        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.RowSpan="2" Style="{StaticResource ContentPanelStyle}">

            <ScrollViewer BorderBrush="CornflowerBlue" BorderThickness="0, 2, 0, 2" Padding="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" Style="{StaticResource MainScrollViewerStyle}">

                <StackPanel Orientation="Vertical">

                    <Border Background="Transparent" BorderBrush="CornflowerBlue" BorderThickness="0,0,0,2" Padding="0" Visibility="{Binding Path=User, Source={StaticResource InputMainViewModel}, Converter={StaticResource UserToVisibilityConverter}}">
                        <StackPanel Orientation="Horizontal" Margin="2">
                            <Image Source="Resources/Filter2HS.png" />
                            <TextBlock Text="Отображать: " VerticalAlignment="Center" Margin="2, 0, 0, 0"/>
                            <ComboBox x:Name="AllVisibleCB" SelectionChanged="ComboBox_SelectionChanged" Margin="0, 0, 0, 4">
                                <ComboBoxItem Content="Все показатели"/>
                                <ComboBoxItem Content="Закрепленные показатели"/>
                            </ComboBox>
                        </StackPanel>
                    </Border>

                    <controls:TreeView x:Name="IndexMarkTreeView" Style="{StaticResource MainTreeViewStyle}" Grid.Column="0" Grid.Row="1"
                     ItemsSource="{Binding VisibilitySections, Source={StaticResource InputMainViewModel}}" SelectedItemChanged="IndexMarkTreeView_SelectedItemChanged" VirtualizingStackPanel.VirtualizationMode="Recycling">

                        <controls:TreeView.ItemTemplate>
                            <common:HierarchicalDataTemplate ItemsSource="{Binding Childs}">
                                <StackPanel Orientation = "Horizontal">
                                    <Image x:Name="SectionImg" Source="{Binding ImagePath}" Width="20" Height="20"/>
                                    <TextBlock Text="{Binding Path=Order}" FontWeight="{Binding IsResponsible, Converter={StaticResource BoolToFontWeightConverter}}"/>
                                    <TextBlock Text=" - " FontWeight="{Binding IsResponsible, Converter={StaticResource BoolToFontWeightConverter}}"/>
                                    <TextBlock Text="{Binding Path=Name}" FontWeight="{Binding IsResponsible, Converter={StaticResource BoolToFontWeightConverter}}"/>
                                    <ToolTipService.ToolTip>
                                        <ToolTip Template="{StaticResource ToolTipTemplate}">
                                            <ToolTip.Content>
                                                <Grid Margin="5, 0, 0, 0" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition/>
                                                        <ColumnDefinition/>
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                        <RowDefinition/>
                                                    </Grid.RowDefinitions>
                                                    <TextBlock Text="{Binding Name}" Grid.ColumnSpan="2" Grid.Row="0" FontSize="12" FontFamily="Times New Roman" FontWeight="Bold" Width="300" TextWrapping="Wrap" Margin="0, 0, 0, 5"/>
                                                    <TextBlock Text="Вес " Grid.Column="0" Grid.Row="1" />
                                                    <TextBlock Text="{Binding Weight}"  Grid.Column="1" Grid.Row="1" Style="{StaticResource ToolTipTextBlockStyle}"/>
                                                    <TextBlock Text="Ответственные " Grid.Column="0" Grid.Row="2"/>
                                                    <ListBox ItemsSource="{Binding Responsibles}" Foreground="DarkBlue" Grid.Column="1" Grid.Row="2" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                                                        <ListBox.ItemContainerStyle>
                                                            <Style TargetType="ListBoxItem">
                                                                <Setter Property="Padding" Value="0" />
                                                            </Style>
                                                        </ListBox.ItemContainerStyle>
                                                    </ListBox>
                                                    <TextBlock Text="Категория " Grid.Column="0" Grid.Row="3"/>
                                                    <TextBlock Text="{Binding Path=Category.Name}" Grid.Column="1" Grid.Row="3" Style="{StaticResource ToolTipTextBlockStyle}"/>
                                                    <TextBlock Text="Вес категории " Grid.Column="0" Grid.Row="4"/>
                                                    <TextBlock Text="{Binding Path=Category.Weight}" Grid.Column="1" Grid.Row="4" Style="{StaticResource ToolTipTextBlockStyle}"/>
                                                    <TextBlock Text="Единица измерения " Grid.Column="0" Grid.Row="5"/>
                                                    <TextBlock Text="{Binding Path=Unit}" Grid.Column="1" Grid.Row="5" Style="{StaticResource ToolTipTextBlockStyle}"/>
                                                </Grid>
                                            </ToolTip.Content>
                                        </ToolTip>
                                    </ToolTipService.ToolTip>
                                </StackPanel>
                            </common:HierarchicalDataTemplate>
                        </controls:TreeView.ItemTemplate>
                    </controls:TreeView>

                </StackPanel>

            </ScrollViewer>

        </StackPanel>

        <controls:GridSplitter Grid.RowSpan="2" Grid.Column="0" Background="CornflowerBlue" Width="6" BorderBrush="Transparent" BorderThickness="0" Style="{StaticResource MainGridSplitterStyle}" MouseLeftButtonUp="GridSplitter_MouseLeftButtonUp"/>

        <sharedcontrols:LoadingBar x:Name="loadingBar" VerticalAlignment="Center" Action="загрузка"
                 HorizontalAlignment="Center" Grid.ColumnSpan="2" Grid.RowSpan="2" Canvas.ZIndex="1"/>

        <Border x:Name="FilterBorder" BorderBrush="CornflowerBlue" BorderThickness="0,2,0,0" Grid.Column="1" Grid.Row="0">
            <StackPanel Orientation="Horizontal" Background="#FF99C1FD" Width="Auto" Height="Auto" VerticalAlignment="Center">
                <TextBlock Text=" Подразделение: " Style="{StaticResource ContentTextStyle}"/>
                <!--<input:AutoCompleteBox x:Name="CatherdaFilter" Width="200" ItemsSource="{Binding Path=Departments, Source={StaticResource InputMainViewModel}}" ToolTipService.ToolTip="Фильтр по подразделению"
                 FilterMode="StartsWith" MinimumPrefixLength="1" DropDownClosing="CatherdaFilter_DropDownClosing" LostFocus="CatherdaFilter_LostFocus" TextChanged="CatherdaFilter_TextChanged">
                    <input:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"/>
                        </DataTemplate>
                    </input:AutoCompleteBox.ItemTemplate>
                </input:AutoCompleteBox>-->
                <ComboBox x:Name="DepFilter" Width="200" ItemsSource="{Binding Path=Departments, Source={StaticResource InputMainViewModel}}" ToolTipService.ToolTip="Фильтр по подразделению" SelectionChanged="CatherdaFilter_SelectionChanged"/>
                <Button Click="Button_Click_1" Margin="2" ToolTipService.ToolTip="Очистить фильтр">
                    <Image Source="Resources/edit-clear.png"/>
                </Button>

                <TextBlock Text=" ФИО: " Style="{StaticResource ContentTextStyle}"/>
                <TextBox x:Name="RespFilter" Width="150" TextChanged="RespFilter_TextChanged" LostFocus="RespFilter_LostFocus" ToolTipService.ToolTip="Фильтр по ФИО"/>

                <TextBlock Text=" Отображать: " Style="{StaticResource ContentTextStyle}"/>
                <ComboBox SelectedIndex="0" x:Name="AnswersFilterCB" SelectionChanged="ComboBox_SelectionChanged_1" ToolTipService.ToolTip="Фильтр по значениям показателя">
                    <ComboBox.Items>
                        <ComboBoxItem Content="Все показатели"/>
                        <ComboBoxItem Content="Заполненные"/>
                        <ComboBoxItem Content="Незаполненные"/>
                    </ComboBox.Items>
                </ComboBox>

            </StackPanel>
        </Border>

        <Border BorderBrush="CornflowerBlue" BorderThickness="0,2,0,2" Grid.Column="1" Grid.Row="1">

            <StackPanel Orientation="Horizontal" Style="{StaticResource ContentPanelStyle2}" Width="Auto" Height="Auto">

                <classes:xDataGrid x:Name="IndexMarkView" ItemsSource="{Binding RespAnswers, Source={StaticResource InputMainViewModel}}" 
                               Style="{StaticResource DataGridStyle}" AutoGenerateColumns="False" LoadingRowGroup="IndexMarkView_LoadingRowGroup"
                               HorizontalScrollBarVisibility="Hidden" VirtualizingStackPanel.VirtualizationMode="Recycling" IsReadOnly="True" RowStyle="{StaticResource StandartNotSelectedDataGridRowStyle}" CellStyle="{StaticResource NotSelectedDataGridCellStyle}">
                    <classes:xDataGrid.Columns>
                        <data:DataGridTextColumn Header="ФИО" Binding="{Binding Resp.ShortName}" IsReadOnly="True"/>
                        <data:DataGridTextColumn Header="Должность" Binding="{Binding Resp.Job}" IsReadOnly="True"/>

                        <data:DataGridTemplateColumn Header="Показатели" IsReadOnly="True">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <classes:xDataGrid x:Name="ChildTable" Visibility="{Binding Path=CurrentChar.IsGraduated, Source={StaticResource InputMainViewModel}, Converter={StaticResource BoolToVisibilityConverter}}"
                                                           BorderThickness="0" BorderBrush="Transparent" ItemsSource="{Binding Answers}" 
                                                           Background="Transparent" RowBackground="Transparent" IsReadOnly="True" AutoGenerateColumns="False" 
                                                           RowStyle="{StaticResource NotSelectedDataGridRowStyle}" CellStyle="{StaticResource NotSelectedDataGridCellStyle}"
                                                           HeadersVisibility="None" Loaded="ChildTable_Loaded">
                                            <classes:xDataGrid.Columns>

                                                <data:DataGridTemplateColumn Header="Градация" IsReadOnly="True">
                                                    <data:DataGridTemplateColumn.CellTemplate>
                                                        <DataTemplate>

                                                            <ListBox ItemsSource="{Binding Gradations}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemContainerStyle="{StaticResource NotSelectedListBoxItemStyle}" Background="Transparent" BorderBrush="Transparent" BorderThickness="0">
                                                                <ListBox.ItemTemplate>
                                                                    <DataTemplate>
                                                                        <StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                                                                            <TextBlock Text="{Binding Name}" TextWrapping="Wrap" ToolTipService.ToolTip="{Binding}"/>
                                                                            <StackPanel Orientation="Horizontal" Visibility="{Binding Volume, Converter={StaticResource NullToVisibilityConverter}}" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                                                                                <TextBlock Text=" - " />
                                                                                <TextBlock Text="{Binding Volume}" Margin="3, 0, 0, 0" />
                                                                            </StackPanel>
                                                                        </StackPanel>
                                                                    </DataTemplate>
                                                                </ListBox.ItemTemplate>
                                                            </ListBox>

                                                        </DataTemplate>
                                                    </data:DataGridTemplateColumn.CellTemplate>
                                                </data:DataGridTemplateColumn>

                                                <data:DataGridTemplateColumn Header="Значение">
                                                    <data:DataGridTemplateColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Loaded="TextBlock_Loaded" HorizontalAlignment="Left" Margin="5, 0, 0, 0" VerticalAlignment="Center" FontWeight="Bold"/>
                                                        </DataTemplate>
                                                    </data:DataGridTemplateColumn.CellTemplate>
                                                </data:DataGridTemplateColumn>

                                            </classes:xDataGrid.Columns>
                                        </classes:xDataGrid>

                                        <ListBox BorderThickness="0" BorderBrush="Transparent" ItemsSource="{Binding Answers}" 
                                         Background="Transparent" Visibility="{Binding Path=CurrentChar.IsGraduated, Source={StaticResource InputMainViewModel}, Converter={StaticResource ContrVisToBoolConverter}}">
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Volume}" FontWeight="Bold" />
                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                        </ListBox>

                                    </StackPanel>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>

                        <data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Click="Button_Click" IsEnabled="{Binding Resp.HasEdit}" Width="20" Height="20" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" Margin="5, 0, 0, 0">
                                        <Image Source="Resources/Actions/Modify_16.png"/>
                                        <interactivity:Interaction.Behaviors>
                                            <classes:ButtonBehavior/>
                                        </interactivity:Interaction.Behaviors>
                                    </Button>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>
                    </classes:xDataGrid.Columns>
                </classes:xDataGrid>

            </StackPanel>

        </Border>

    </Grid>

</navigation:Page>